package com.zerui.manager.app.accessauthdevice.scheduler;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.zerui.manager.accessauthorization.AccessAuth;
import com.zerui.manager.accessauthorization.domainservice.AccessAuthRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wh
 * @create_time 2023-08-23 15:33
 *
 * 同步设备管理 - 门禁相关设备
 */
@Slf4j
@Component
public class AccessAuthDistributeScheduler {

    @Resource
    private AccessAuthRepository accessAuthRepository;

    //如果不是始终有效和全体有效  门禁授权重新下发
    @Scheduled(cron = "0 0 0 ? * *")
    private void distributeDeviceAuthScheduler() {
        List<AccessAuth> accessAuthList = accessAuthRepository.selectAll();
        if(CollectionUtils.isNotEmpty(accessAuthList)){
            accessAuthList.forEach(e->{
                if(e.getDateType().equals(1) || e.getTimeType().equals(1)){
                    accessAuthRepository.distributeAccessAuth(e.getId());
                }
            });
        }
    }


}
